//
//  ViewController.swift
//  Sqlite-FDBM
//
//  Created by 朱益锋 on 15/12/23.
//  Copyright © 2015年 朱益锋. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    var userInfos:NSMutableArray?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.userInfos = NSMutableArray()
        
        for _ in 1..<100{
            let ran = random() % 100
            let userInfo = UserInfo()
            userInfo.name = "zyf\(ran)"
            userInfo.phone = "1535603\(ran)"
            userInfo.userId = "2314\(ran)"
            self.userInfos!.addObject(userInfo)
        }
        
        shareDataBaseManager.creatUserTable()
    }

    @IBAction func insert() {
        for ob  in self.userInfos!{
            shareDataBaseManager.inserUserToDB(ob as! UserInfo)
        }
    }



    @IBAction func updata() {
        shareDataBaseManager.updataUserInfo("zhuyifeng", phone: "15356032778", inUserId: "231483")
    }
    
    @IBAction func select() {
        let arr = shareDataBaseManager.getUserInfo()
        for ob in arr{
            print(ob)
            let dic = ob as! NSDictionary
            let userInfo = UserInfo()
            userInfo.name = dic["name"] as? String
            userInfo.phone = dic["phone"] as? String
            userInfo.userId = dic["userId"] as? String
        }
    }
    
    @IBAction func delete() {
        shareDataBaseManager.deleteUserInfo()
    }
}

